#pragma once

#include <assert.h>
#include "common.h"
#include "ResultStorage.h"
#include "GeneratorTester.h"

template
<
	class TResult, 
	class TGenerator
>
class Enumerator 
	: public GeneratorTester<TGenerator, TResult>
{
public:

	typedef GeneratorTester<TGenerator, TResult> Tester;
	typedef typename generator_traits<TGenerator>::Configuration Configuration;
	typedef ResultStorage<Configuration, TResult> Storage;
	typedef SimpleIterator<Configuration> Iterator;

	Enumerator(
		Iterator *configurationIterator,
		int maxSequenceLength) 
		: _configurationIterator(configurationIterator), 
		_maxSequenceLength(maxSequenceLength)
	{
	}

	void enumerate(
		TGenerator *generator, 
		Storage *callback)
	{
		while(_configurationIterator->moveNext())
		{
			generator_traits<TGenerator>::setConfiguration(
				generator, _configurationIterator->current());
			TResult res = Tester::test(generator, _maxSequenceLength);
			callback->store(_configurationIterator->current(), res);
		}
	}

private:
	Iterator *_configurationIterator;	
	int _maxSequenceLength;
};
